#!/usr/bin/python
#-*- coding:utf-8 -*-

import json
import requests
import warnings
import sys
import warnings

def gettoken(corpid,corpsecret):
    Url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s' % (corpid,corpsecret)
        UrlContext = requests.get(Url).text
	    Content = eval(UrlContext)
	    Token = Content['access_token']
		return Token
		    	
def sendmessage(Userid,Text):
	submiturl = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}'.format(token)
	data = {"touser":Userid,"msgtype":"text","agentid":"0","text":{"content":Text},"safe":"0"}
	data = json.dumps(data,ensure_ascii=False)
	submitdata = requests.post(submiturl,data)
	content=submitdata.text
	print content
							
if __name__ == '__main__':
	warnings.filterwarnings('ignore')
	token=gettoken(CORPID,CORPSECRET)
	print token
	userid = sys.argv[1]
	text = sys.argv[2]
    sendmessage(userid,text)